//
//  HLadvsTableViewCell.m
//  huiliantong
//
//  Created by hlt on 15/8/12.
//  Copyright (c) 2015年 hlt. All rights reserved.
//

#import "HLadvsTableViewCell.h"
#import "RecommendModel.h"
#import "HLTShopViewController.h"
@implementation HLadvsTableViewCell

- (void)awakeFromNib {
    // Initialization code
    //确保只加载一次
    _biaoji=YES;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}





-(void) start
{
    
    if (_biaoji) {
        [self setupViews];
        _biaoji=NO;
    }
    
    
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}



#pragma mark -在这里设置滚动图的图片
- (void)setupViews
{
    NSMutableArray *items = [NSMutableArray arrayWithCapacity:3];
    int count=0;
    
    for (int i=0; i<[_imagearray count]; i++) {
        UIImage *image = [[UIImage alloc] init] ;
//        [self.shopImage setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"bg_customReview_image_default"]];
        image = [UIImage imageNamed:@"bg_customReview_image_default"];
        
        RecommendModel *recommend=_imagearray[i];
        //
        NSString *imageUrl =  [imageurl stringByAppendingString:recommend.shop_image];
        NSLog(@"%@",imageUrl);
        NSURL *url1= [[NSURL alloc]initWithString:imageUrl];
        UIImageView *imagg=[UIImageView new];
        [imagg setImageWithURL:url1 placeholderImage:image];
        
//           [imagg stretchableImageWithLeftCap ]
//        imagg resizableSnapshotViewFromRect:<#(CGRect)#> afterScreenUpdates:<#(BOOL)#> withCapInsets:<#(UIEdgeInsets)#>
//        - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
        
        SGFocusImageItem *item1 = [[SGFocusImageItem alloc] initWithTitle:@"" imageview:imagg tag:count ];
        count++;
        [items addObject:item1];
        
    }
    
    [items removeLastObject];
    UIScreen *currentScreen = [UIScreen mainScreen];
    CGFloat aa=screen_width/1.5;
    SGFocusImageFrame *imageFrame = [[SGFocusImageFrame alloc]    initWithFramearray:CGRectMake(0, 0, currentScreen.applicationFrame.size.width, aa) delegate:self focusImageItems:items];
    [self.pageview insertSubview:imageFrame atIndex:0];
    
    
}

#pragma mark -
- (void)foucusImageFrame:(SGFocusImageFrame *)imageFrame didSelectItem:(SGFocusImageItem *)item
{

    
    
//    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"点击了广告"   message:nil delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
//    [alert show];
    
    //     [SJAvatarBrowser showImage:(UIImageView*)item.imageview];
    
     NSLog(@"%ld tapped", (long)item.tag);
    
    
    
    RecommendModel *recommend = _imagearray[item.tag];
    
    HLTShopViewController *shopvc=[[HLTShopViewController alloc]init];
    shopvc.biaozhi=YES;
    shopvc.shopcontent=recommend;
    shopvc.hidesBottomBarWhenPushed = YES;
    [self.parent.navigationController pushViewController:shopvc animated:YES];
    
    
}





@end





